home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 January / macpower199701.bin / AMUG / Programming_10 / Videotoolbox 96-08-22-c.sit / VideoToolbox / VideoToolboxSources / Shuffle.c < prev    next >
MacBinary  |  1995-07-19  |  1.8 KB  |  [TEXT/CWIE]

open in: MacOS 8.1     |     Win98     |     DOS

view JSON data     |     view as text

This file was processed as: MacBinary (archive/macBinary).

You can browse this item here: Shuffle.c

ConfidenceProgramDetectionMatch TypeSupport
66% dexvert Compact Compressed (Unix) (archive/compact) ext Supported
10% dexvert MacBinary (archive/macBinary) fallback Supported
1% dexvert Text File (text/txt) fallback Supported
100% file MacBinary II, inited, Wed Jul 19 19:45:55 1995, modified Wed Jul 19 19:45:55 1995, creator 'CWIE', type ASCII, 1128 bytes "Shuffle.c" , at 0x4e8 456 bytes resource default (weak)
99% file data default
74% TrID Macintosh plain text (MacBinary) default
25% TrID MacBinary 2 default (weak)
100% siegfried fmt/1762 MacBinary (II) default
100% lsar MacBinary default


id metadata
keyvalue
macFileType[TEXT]
macFileCreator[CWIE]



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 00 09 53 68 75 66 66 6c | 65 2e 63 00 00 00 00 00 |..Shuffl|e.c.....|
|00000010| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000020| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000030| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000040| 00 54 45 58 54 43 57 49 | 45 01 00 00 00 00 00 00 |.TEXTCWI|E.......|
|00000050| 00 00 00 00 00 04 68 00 | 00 01 c8 ac 33 49 b3 ac |......h.|....3I..|
|00000060| 33 49 b3 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |3I......|........|
|00000070| 00 00 00 00 00 00 00 00 | 00 00 81 81 c2 5a 00 00 |........|.....Z..|
|00000080| 2f 2a 0d 53 68 75 66 66 | 6c 65 2e 63 0d 4c 69 6b |/*.Shuff|le.c.Lik|
|00000090| 65 20 74 68 65 20 53 74 | 61 6e 64 61 72 64 20 43 |e the St|andard C|
|000000a0| 20 66 75 6e 63 74 69 6f | 6e 20 71 73 6f 72 74 28 | functio|n qsort(|
|000000b0| 29 2c 20 53 68 75 66 66 | 6c 65 20 72 65 6f 72 64 |), Shuff|le reord|
|000000c0| 65 72 73 20 74 68 65 20 | 65 6c 65 6d 65 6e 74 73 |ers the |elements|
|000000d0| 20 6f 66 0d 61 6e 20 61 | 72 72 61 79 2c 20 62 75 | of.an a|rray, bu|
|000000e0| 74 20 53 68 75 66 66 6c | 65 20 70 72 6f 64 75 63 |t Shuffl|e produc|
|000000f0| 65 73 20 61 20 72 61 6e | 64 6f 6d 69 7a 65 64 20 |es a ran|domized |
|00000100| 73 65 71 75 65 6e 63 65 | 2e 0d 0d 48 49 53 54 4f |sequence|...HISTO|
|00000110| 52 59 3a 0d 33 2f 31 39 | 2f 39 34 09 64 67 70 09 |RY:.3/19|/94.dgp.|
|00000120| 72 65 77 72 6f 74 65 20 | 69 74 20 74 6f 20 61 63 |rewrote |it to ac|
|00000130| 63 65 70 74 20 61 6e 20 | 61 72 62 69 74 72 61 72 |cept an |arbitrar|
|00000140| 79 20 65 6c 65 6d 65 6e | 74 20 73 69 7a 65 2e 20 |y elemen|t size. |
|00000150| 49 74 20 70 72 6f 62 61 | 62 6c 79 20 6e 6f 77 0d |It proba|bly now.|
|00000160| 72 75 6e 73 20 74 65 6e | 20 74 69 6d 65 73 20 73 |runs ten| times s|
|00000170| 6c 6f 77 65 72 20 74 68 | 61 6e 20 77 68 65 6e 20 |lower th|an when |
|00000180| 69 74 20 6f 6e 6c 79 20 | 61 63 63 65 70 74 65 64 |it only |accepted|
|00000190| 20 73 68 6f 72 74 73 2e | 20 49 66 20 74 68 65 20 | shorts.| If the |
|000001a0| 6c 6f 73 73 20 6f 66 20 | 73 70 65 65 64 0d 6d 61 |loss of |speed.ma|
|000001b0| 74 74 65 72 73 20 74 6f | 20 61 6e 79 62 6f 64 79 |tters to| anybody|
|000001c0| 2c 20 6c 65 74 20 6d 65 | 20 6b 6e 6f 77 2c 20 61 |, let me| know, a|
|000001d0| 73 20 69 74 20 77 6f 75 | 6c 64 20 62 65 20 65 61 |s it wou|ld be ea|
|000001e0| 73 79 20 74 6f 20 61 64 | 64 20 66 61 73 74 20 73 |sy to ad|d fast s|
|000001f0| 70 65 63 69 61 6c 2d 63 | 61 73 65 0d 63 6f 64 65 |pecial-c|ase.code|
|00000200| 20 66 6f 72 20 61 20 66 | 65 77 20 70 6f 70 75 6c | for a f|ew popul|
|00000210| 61 72 20 65 6c 65 6d 65 | 6e 74 20 73 69 7a 65 73 |ar eleme|nt sizes|
|00000220| 2c 20 65 2e 67 2e 20 73 | 69 7a 65 6f 66 28 73 68 |, e.g. s|izeof(sh|
|00000230| 6f 72 74 29 2e 0d 2a 2f | 0d 23 69 6e 63 6c 75 64 |ort)..*/|.#includ|
|00000240| 65 20 22 56 69 64 65 6f | 54 6f 6f 6c 62 6f 78 2e |e "Video|Toolbox.|
|00000250| 68 22 0d 0d 76 6f 69 64 | 20 53 68 75 66 66 6c 65 |h"..void| Shuffle|
|00000260| 28 76 6f 69 64 20 2a 61 | 72 72 61 79 2c 6c 6f 6e |(void *a|rray,lon|
|00000270| 67 20 65 6c 65 6d 65 6e | 74 73 2c 73 69 7a 65 5f |g elemen|ts,size_|
|00000280| 74 20 65 6c 65 6d 65 6e | 74 53 69 7a 65 29 0d 7b |t elemen|tSize).{|
|00000290| 0d 09 6c 6f 6e 67 20 69 | 2c 6a 3b 0d 09 76 6f 69 |..long i|,j;..voi|
|000002a0| 64 20 2a 73 63 72 61 74 | 63 68 3b 0d 09 64 6f 75 |d *scrat|ch;..dou|
|000002b0| 62 6c 65 20 77 6f 72 6b | 41 72 65 61 5b 32 35 36 |ble work|Area[256|
|000002c0| 2f 73 69 7a 65 6f 66 28 | 64 6f 75 62 6c 65 29 5d |/sizeof(|double)]|
|000002d0| 3b 0d 09 0d 09 61 73 73 | 65 72 74 28 73 69 7a 65 |;....ass|ert(size|
|000002e0| 6f 66 28 63 68 61 72 29 | 3d 3d 31 29 3b 0d 09 23 |of(char)|==1);..#|
|000002f0| 69 66 20 4d 41 43 5f 43 | 0d 09 09 61 73 73 65 72 |if MAC_C|...asser|
|00000300| 74 28 53 74 61 63 6b 53 | 70 61 63 65 28 29 3e 34 |t(StackS|pace()>4|
|00000310| 30 30 30 29 3b 0d 09 23 | 65 6e 64 69 66 0d 09 69 |000);..#|endif..i|
|00000320| 66 28 73 69 7a 65 6f 66 | 28 77 6f 72 6b 41 72 65 |f(sizeof|(workAre|
|00000330| 61 29 3c 65 6c 65 6d 65 | 6e 74 53 69 7a 65 29 7b |a)<eleme|ntSize){|
|00000340| 0d 09 09 73 63 72 61 74 | 63 68 3d 6d 61 6c 6c 6f |...scrat|ch=mallo|
|00000350| 63 28 65 6c 65 6d 65 6e | 74 53 69 7a 65 29 3b 0d |c(elemen|tSize);.|
|00000360| 09 09 61 73 73 65 72 74 | 28 73 63 72 61 74 63 68 |..assert|(scratch|
|00000370| 21 3d 4e 55 4c 4c 29 3b | 0d 09 7d 65 6c 73 65 20 |!=NULL);|..}else |
|00000380| 73 63 72 61 74 63 68 3d | 77 6f 72 6b 41 72 65 61 |scratch=|workArea|
|00000390| 3b 0d 09 66 6f 72 28 69 | 3d 30 3b 69 3c 65 6c 65 |;..for(i|=0;i<ele|
|000003a0| 6d 65 6e 74 73 3b 69 2b | 2b 29 7b 0d 09 09 6a 3d |ments;i+|+){...j=|
|000003b0| 6e 72 61 6e 64 28 65 6c | 65 6d 65 6e 74 73 29 3b |nrand(el|ements);|
|000003c0| 0d 09 09 69 66 28 69 3d | 3d 6a 29 63 6f 6e 74 69 |...if(i=|=j)conti|
|000003d0| 6e 75 65 3b 0d 09 09 2f | 2a 20 73 77 61 70 20 69 |nue;.../|* swap i|
|000003e0| 2d 74 68 20 61 6e 64 20 | 6a 2d 74 68 20 65 6c 65 |-th and |j-th ele|
|000003f0| 6d 65 6e 74 73 20 2a 2f | 0d 09 09 6d 65 6d 63 70 |ments */|...memcp|
|00000400| 79 28 73 63 72 61 74 63 | 68 2c 28 63 68 61 72 20 |y(scratc|h,(char |
|00000410| 2a 29 61 72 72 61 79 2b | 6a 2a 65 6c 65 6d 65 6e |*)array+|j*elemen|
|00000420| 74 53 69 7a 65 2c 65 6c | 65 6d 65 6e 74 53 69 7a |tSize,el|ementSiz|
|00000430| 65 29 3b 0d 09 09 6d 65 | 6d 63 70 79 28 28 63 68 |e);...me|mcpy((ch|
|00000440| 61 72 20 2a 29 61 72 72 | 61 79 2b 6a 2a 65 6c 65 |ar *)arr|ay+j*ele|
|00000450| 6d 65 6e 74 53 69 7a 65 | 2c 28 63 68 61 72 20 2a |mentSize|,(char *|
|00000460| 29 61 72 72 61 79 2b 69 | 2a 65 6c 65 6d 65 6e 74 |)array+i|*element|
|00000470| 53 69 7a 65 2c 65 6c 65 | 6d 65 6e 74 53 69 7a 65 |Size,ele|mentSize|
|00000480| 29 3b 0d 09 09 6d 65 6d | 63 70 79 28 28 63 68 61 |);...mem|cpy((cha|
|00000490| 72 20 2a 29 61 72 72 61 | 79 2b 69 2a 65 6c 65 6d |r *)arra|y+i*elem|
|000004a0| 65 6e 74 53 69 7a 65 2c | 73 63 72 61 74 63 68 2c |entSize,|scratch,|
|000004b0| 65 6c 65 6d 65 6e 74 53 | 69 7a 65 29 3b 0d 09 7d |elementS|ize);..}|
|000004c0| 0d 09 69 66 28 73 63 72 | 61 74 63 68 21 3d 77 6f |..if(scr|atch!=wo|
|000004d0| 72 6b 41 72 65 61 29 66 | 72 65 65 28 73 63 72 61 |rkArea)f|ree(scra|
|000004e0| 74 63 68 29 3b 0d 7d 0d | 00 00 00 00 00 00 00 00 |tch);.}.|........|
|000004f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000500| 00 00 01 00 00 00 01 76 | 00 00 00 76 00 00 00 52 |.......v|...v...R|
|00000510| 00 00 1c ff ff 00 00 00 | 00 00 52 00 00 00 2a ff |........|..R...*.|
|00000520| fe 00 00 03 e1 00 52 00 | 00 00 2e ff ff 00 00 00 |......R.|........|
|00000530| 09 53 68 75 66 66 6c 65 | 2e 63 02 00 00 00 54 45 |.Shuffle|.c....TE|
|00000540| 58 54 43 57 49 45 01 00 | 00 14 05 a0 00 00 00 00 |XTCWIE..|........|
|00000550| 00 00 54 45 58 54 43 57 | 49 45 01 00 00 14 05 a0 |..TEXTCW|IE......|
|00000560| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000570| 00 00 a3 a8 32 6d 00 00 | 04 68 00 00 01 c8 6e ff |....2m..|.h....n.|
|00000580| ff 00 00 03 de 00 52 00 | 00 00 72 ff ff 00 00 03 |......R.|..r.....|
|00000590| df 00 52 00 00 00 90 ff | ff 00 00 00 00 00 52 00 |..R.....|......R.|
|000005a0| 00 00 94 ff ff 00 00 00 | 00 00 52 00 00 00 98 ff |........|..R.....|
|000005b0| ff 00 00 00 00 00 52 00 | 00 00 9c ff fe 00 00 00 |......R.|........|
|000005c0| 7a 00 52 00 00 00 a8 ff | ff 00 00 00 00 00 52 00 |z.R.....|......R.|
|000005d0| 00 00 ac ff ff 00 00 00 | 00 00 52 00 00 00 b6 ff |........|..R.....|
|000005e0| ff 00 00 00 00 00 52 00 | 00 00 e2 ff ff 00 00 03 |......R.|........|
|000005f0| df 00 52 00 00 00 e8 ff | ff 00 00 03 de 00 52 00 |..R.....|......R.|
|00000600| 00 00 00 1e 00 2a 00 1c | 01 81 02 18 00 2a 00 1c |.....*..|.....*..|
|00000610| 01 6b 01 53 00 00 00 00 | 00 00 00 00 00 00 00 00 |.k.S....|........|
|00000620| 00 00 00 00 00 48 00 09 | 4d 6f 6e 61 63 6f 00 00 |.....H..|Monaco..|
|00000630| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|00000640| 00 00 00 00 00 00 00 00 | 00 03 00 04 00 3d 00 1c |........|.....=..|
|00000650| 01 94 02 18 00 3d 00 1c | 01 94 02 18 ac 33 11 78 |.....=..|.....3.x|
|00000660| 00 00 03 78 00 00 03 78 | 00 00 01 7c 00 00 00 00 |...x...x|...|....|
|00000670| 00 04 00 01 00 01 00 00 | 01 00 00 00 01 76 00 00 |........|.....v..|
|00000680| 00 76 00 00 00 52 00 59 | 82 58 2a 9a 00 00 00 1c |.v...R.Y|.X*.....|
|00000690| 00 52 00 01 4d 50 53 52 | 00 01 00 12 4d 57 42 42 |.R..MPSR|....MWBB|
|000006a0| 00 00 00 2a 03 f0 ff ff | 00 00 00 00 00 00 00 00 |...*....|........|
|000006b0| 03 ed ff ff 00 00 00 22 | 00 00 00 00 03 f0 ff ff |......."|........|
|000006c0| 00 00 00 6e 00 00 00 00 | 00 00 00 00 00 00 00 00 |...n....|........|
|000006d0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000006e0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
|000006f0| 00 00 00 00 00 00 00 00 | 00 00 00 00 00 00 00 00 |........|........|
+--------+-------------------------+-------------------------+--------+--------+